package cn.edu.scau.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.scau.dao.WorkPlanMapper;
import cn.edu.scau.entity.WorkPlan;
import cn.edu.scau.service.WorkPlanService;

@Service
public class WorkPlanServiceImpl implements WorkPlanService{
	@Autowired
	WorkPlanMapper workPlanMapper;

	@Override
	public boolean insert(WorkPlan workPlan) {
		int line = workPlanMapper.insertSelective(workPlan);
		return line ==1? true:false;
	}

	@Override
	public boolean update(WorkPlan workPlan) {
		int line = workPlanMapper.updateByPrimaryKeySelective(workPlan);
		return line ==1? true:false;
	}

	@Override
	public boolean delete(Date workdate, Integer nurseid) {
		int line = workPlanMapper.deleteByPrimaryKey(workdate, nurseid);
		return line ==1? true:false;
	}

	@Override
	public WorkPlan selectByPrimaryKey(Date workdate, Integer nurseid) {
		return workPlanMapper.selectByPrimaryKey(workdate, nurseid);
	}

	@Override
	public List<WorkPlan> selectByNurseID(Integer nurseid) {
		if(nurseid!=null&&nurseid<1){
			System.out.println("根据护士编号查询工作计划时护士编号错误");
			return null;
        }
		return workPlanMapper.selectWithNurseID(nurseid);
	}

	@Override
	public List<WorkPlan> selectAll() {
		return workPlanMapper.selectAll();
	}

	@Override
	public List<WorkPlan> find(Date workdate, Integer nurseid, String nursename) {
		if(workdate!=null&&StringUtils.isBlank(workdate.toString())){
			workdate=null;
        }
		if(nurseid!=null&&nurseid<1){
			nurseid=null;
        }
        if(StringUtils.isBlank(nursename)){
        	nursename=null;
        }
		return workPlanMapper.find(workdate, nurseid, nursename);
	}

	@Override
	public List<WorkPlan> findWithNurseID(Date workdate, Integer nurseid, String nursename) {
		if(workdate!=null&&StringUtils.isBlank(workdate.toString())){
			workdate=null;
        }
		if(nurseid!=null&&nurseid<1){
			System.out.println("根据护士编号查询工作计划时护士编号错误");
			return null;
        }
        if(StringUtils.isBlank(nursename)){
        	nursename=null;
        }
		return workPlanMapper.findWithNurseID(workdate, nurseid, nursename);
	}
	
	
}
